//
//  ProfitRecordViewController.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/9/21.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "ProfitRecordViewController.h"
#define Reuse1 @"reuse1"
#define Reuse2 @"reuse2"
#import "ProfitRecord1TableViewCell.h"
#import "ProfitRecord2TableViewCell.h"
#import "DrawMoneyNet.h"

@interface ProfitRecordViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *profits;

@end

@implementation ProfitRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self getRecoder];
}

- (void)getRecoder {
    if(self.isMiun) {
        [DrawMoneyNet DrawMoneyRecoder:^(id result, NSError *error) {
            if(result) {
                self.profits = result;
                [self.tableView reloadData];
            }
        }];
    }else {
        [DrawMoneyNet PROFITRecoder:^(id result, NSError *error) {
            if(result) {
                self.profits = result;
                [self.tableView reloadData];
            }
        }];
    }
}

- (void)setupUI {
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.title = self.vcTitle;
    [self.tableView registerNib:[UINib nibWithNibName:@"ProfitRecord1TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:Reuse1];
    [self.tableView registerNib:[UINib nibWithNibName:@"ProfitRecord2TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:Reuse2];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ProfitRecord2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Reuse2];
    [cell setupUI:self.profits[indexPath.row] symbol:self.isMiun];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.profits.count;
}

@end
